package anul_2014.Programare;

import java.util.Scanner;

public class Citire {

	public static Scanner sc = new Scanner(System.in);

	public static int citireInt() {
		int x;
		String a;
		System.out.println("Nr= ");
		while (true) {
			a = sc.next();
			try {
				x = Integer.parseInt(a);
				break;
			} catch (NumberFormatException e) {
				System.out.println("Introduceti valoarea corecta! ");
				continue;
			}
		}
		return x;
	}
	public static short citireShort() {
		short x;
		String a;
		System.out.println("Nr= ");
		while (true) {
			a = sc.next();
			try {
				x = Short.parseShort(a);
				break;
			} catch (NumberFormatException e) {
				System.out.println("Introduceti valoarea corecta! ");
				continue;
			}
		}
		return x;
	}
	public static byte citireByte() {
		byte x;
		String a;
		System.out.println("Nr= ");
		while (true) {
			a = sc.next();
			try {
				x = Byte.parseByte(a);
				break;
			} catch (NumberFormatException e) {
				System.out.println("Introduceti valoarea corecta! ");
				continue;
			}
		}
		return x;
	}
	public static long citireLong() {
		long x;
		String a;
		System.out.println("Nr= ");
		while (true) {
			a = sc.next();
			try {
				x = Long.parseLong(a);
				break;
			} catch (NumberFormatException e) {
				System.out.println("Introduceti valoarea corecta! ");
				continue;
			}
		}
		return x;
	}
	public static float citireFloat() {
		float x;
		String a;
		System.out.println("Nr= ");
		while (true) {
			a = sc.next();
			try {
				x = Float.parseFloat(a);
				break;
			} catch (NumberFormatException e) {
				System.out.println("Introduceti valoarea corecta! ");
				continue;
			}
		}
		return x;
	}
	public static double citireDouble() {
		double x;
		String a;
		System.out.println("Nr= ");
		while (true) {
			a = sc.next();
			try {
				x = Double.parseDouble(a);
				break;
			} catch (NumberFormatException e) {
				System.out.println("Introduceti valoarea corecta! ");
				continue;
			}
		}
		return x;
	}
	public static boolean citireBoolean() {
		boolean x;
		String a;
		System.out.println("Nr= ");
		while (true) {
			a = sc.next();
			try {
				x = Boolean.parseBoolean(a);
				break;
			} catch (NumberFormatException e) {
				System.out.println("Introduceti valoarea corecta! ");
				continue;
			}
		}
		return x;
	}
	// private static String getInput(String prompt) {
	// BufferedReader stdin = new BufferedReader(new
	// InputStreamReader(System.in));
	//
	// System.out.println(prompt);
	// System.out.flush();
	//
	// try {
	// return stdin.readLine();
	// } catch (Exception e) {
	// return "Error: " + e.getMessage();
	// }
	// }
}
